from typing import List


width, height, byte_len = 128, 64, 8
array_width, array_height = width // byte_len, height

file_name = "picture_good.txt"
target_file_name = "picture_good_tran.inc"


def translate(base_pos: int, array: List):
    for offset in range(byte_len):
        value = 0x00

        for j in range(byte_len):
            value = value | (
                int(array[base_pos + array_width * j] & (0x80 >> offset) is not 0) << j)

        yield value


if __name__ == "__main__":
    with open(file_name) as f:
        array = [i for i in map(lambda v: int(
            v, 16), f.read().replace(' ', '').split(','))]

    result = [k for i in range(0, array_height, byte_len) for j in range(
        array_width) for k in translate(i * array_width + j, array)]

    print(result)

    with open(target_file_name, mode='w') as f:
        count = 0

        for i in result:
            f.write(f"{hex(i)},\t")
            count = count + 1

            if count % array_width == 0:
                f.write('\n')
